home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1012 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. Path: news.sprintlink.net!datalytics!news
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Are Pure Functions always Virtual????
  5. Date: 8 Jan 1996 19:40:24 GMT
  6. Organization: Datalytics, Inc
  7. Message-ID: <4crrv8$h4r@gold.datalytics.com>
  8. References: <4cilse$5li@news2.deltanet.com>
  9. NNTP-Posting-Host: pc071.datalytics.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
  14.  
  15. olivas@deltanet.com (Sergio Olivas) wrote:
  16. >
  17. >I have a base class for accessing databases (BC++), the base class is
  18. >made of only pure virtual functions.  Two derived classes are written,
  19. [snip]
  20. >Since I've heard that using virtual functions really eats into the 64k
  21. >automatic data segment, as well as adding overhead, is the 
  22.  
  23. This is true only insofar as there is a vtable (virtual 
  24. function table) for classes with virtual functions--though it 
  25. is shared among all instances of each class--and that each 
  26. object with virtual functions carries a pointer to the vtable.
  27.  
  28. 'virtual'
  29. >keyword really needed. -- and does it make any difference, assuming
  30. >I'm not going to further derive another class from the newly derived
  31. >class (in this case DB_BASE_PDX) ???
  32.  
  33. >eg..
  34. >  class DB_BASE {
  35. >{  ...
  36. >   virtual int NextRecord(int TableID) = 0;
  37. >  ..^^^^^ is this needed?
  38. > };
  39.  
  40. >The derived classes are something like
  41. >  class DB_BASE_PDX : public DB_BASE
  42. >  {
  43. >    ...
  44. >     int NextRecord(int TableID);
  45. >   ...
  46. >   }
  47.  
  48. Absolutely.  There is no such thing as a "pure" function.  
  49. There are only "pure virtual" functions.  In other words, 
  50. "pure" is a modifier of "virtual" and not of "function."
  51.  
  52. The only purpose of a "pure virtual" function is to specify an 
  53. interface required of classes derived from the abstract base 
  54. class (so named because you cannot instantiate an object of a 
  55. class with pure virtual functions--it is, thus, abstract).  
  56. The virtual function mechanism is what allows for this 
  57. interface commonality among classes derived from the ABC.  You 
  58. can then declare a pointer to the ABC and assign it the 
  59. address of any object of a derived type.  All derived types 
  60. will adhere to the ABC's interface, so the ABC pointer can 
  61. invoke that interface on any derived class object.
  62.  
  63. -- 
  64. Robert Stewart        | My opinions are usually my own.
  65. Datalytics, Inc.
  66. (513)226-7700
  67. stew@datalytics.com
  68.  
  69.  
  70.